//弹出的主题池指标关系面板
function show_win_ztcrep(){
    var psize_sub = 10; 
    var grid;
    var refid;
    var xg = Ext.grid;  
    re = Ext.ComponentMgr.get("ztc").getSelectionModel().getSelected();
    if (re == null || re == "") {
        Ext.Msg.alert('提示', '请勾选需要关联的主题池！');
    } else{
        var openUrl = basePath
        + 'JarpListener?className=cn.com.jsepc.rep.subject_pool.subject_poolGrid';
        openUrl += '&methodName=getsubrepGrid&paramCount=3';
   
        var jReader1 = new Ext.data.JsonReader({
            root: 'data', 
            totalProperty: 'totalCount',
            fields : [{
                name : 'refID'
            },{
                name : 'subjectID'
            },{
                name:'repID'
            },{
                name:'subName'
            },{
                name:'repname'
            }]
        });
	
        var store = new Ext.data.Store({
            autoLoad:true,
            url:openUrl,
            reader : jReader1,
            baseParams : { 
                param_0 : 0, 
                param_1 : psize_sub,
                param_2 : re.data.subID 
            }
        });
       
        store.setDefaultSort('refID', 'ASC');
        var sm = new xg.CheckboxSelectionModel({  });
	
        var cm = new xg.ColumnModel( [
            sm,							
            {
                hidden:true,
                id : 'refID',
                name       :'refID',
                header   : '主题池指标关系编号', 
                sortable : true, 
                dataIndex: 'refID'
            },
            {
                hidden:true,
                id:"subjectID",
                name       :'subjectID',
                header   : '主题池编号',
                sortable : true, 
                dataIndex: 'subjectID'
            },{
                hidden:true,
                id:"repID",
                name       :'repID',
                header   : '指标编号', 
                sortable : true, 
                dataIndex: 'repID'
            },{
                name       :'subName',
                header   : '主题池名称', 
                width: 120,
                sortable : true, 
                dataIndex: 'subName'
            },{
                name       :'repname',
                header   : '指标名称', 
                width: 120,
                sortable : true, 
                dataIndex: 'repname'
            }
            ]);
	     
        cm.defaultSortable = true;
        grid = new Ext.grid.GridPanel({
            id:'crp',
            region: 'center',
            viewConfig: {
                forceFit: true
            }, 
            store:store,
            sm:sm,
            cm:cm,  
            columnLines:true,
            height:400,
            width: 500,
            stateful: true,
            stateId: 'grid',
            bbar: new Ext.PagingToolbar({
                store: store,
                paramNames : {
                    start : 'param_0',
                    limit : 'param_1'
                }, 
                emptyMsg : '没有记录',
                displayInfo: true,           
                pageSize: psize_sub,
                listeners:{
                    beforechange:function(bar,params){
                        bar.store.setBaseParam("param_2",re.data.subID);
                    }
                }
            })
        }); 
    
        var win = new Ext.Window({
        
            title: '主题池指标列表',           
            closable:true,
            width:700,
            height:420,
            modal:true,
            plain:true,
            layout: 'border',
            tbar : ['-', 
            {
                text:'新增',
                handler : function() {                   
                    window.showModalDialog("subject_report.jsp?subID="+re.data.subID, '','dialogWidth=900px;dialogHeight=550px;status:no;resizable:yes;');	   
                    grid.store.reload();
                }
        
            },'-',{
                text:'删除',
                handler : function() {
                    var checkse= Ext.ComponentMgr.get("crp").getSelectionModel().getSelections();
                    
                    if(checkse == null  || checkse == "")
                    {
                        Ext.Msg.alert('提示','请勾选需要删除的主题池！');
                    }else{
                        deleteFrom(checkse);
                    }
                }  
            },'-',{
                text:'关闭',
                handler:function(){
                    win.close();
                }
            }
            ],
            items: [grid]
        });
      
        //删除
        function  deleteFrom(checkse) {
            Ext.MessageBox.show({
                title:'提示框',
                msg: ' 确定删除吗',                
                buttons:{
                    'yes':'确定',
                    'no': '取消'
                },
                fn: showResult,
                icon: Ext.MessageBox.QUESTION
            });
            function showResult(btn){
                if(btn == 'yes'){ 
                    var selections = grid.getSelectionModel().getSelections();
                    var refid=new Array(selections.length);
                    for(var i=0;i<selections.length;i++)
                    {
                        refid[i]=selections[i].get("refID");
                    }
                    var saveItemInfoUrl = "";
                    saveItemInfoUrl = '?className=cn.com.jsepc.rep.subject_pool.subject_poolGrid';
                    saveItemInfoUrl += '&methodName=SubjectRepDelete';
                    saveItemInfoUrl += '&paramCount=1'+'&param_0='+refid;
      
                    saveItemInfoUrl = basePath + 'JarpListener' + saveItemInfoUrl;
                    httpR_itemInfo = getXMLHttpRequest();
                    httpR_itemInfo.onreadystatechange = returnDelete;
                    httpR_itemInfo.open("POST", saveItemInfoUrl, true);
                    httpR_itemInfo.send();
                }else if( btn == 'no')
                {
                    return;
                }
            }       
        }
        function returnDelete() {
            if (httpR_itemInfo.readyState == 4) {
                if (httpR_itemInfo.status == 200) {
                    var ret = httpR_itemInfo.responseText;
                    if (ret=='true'){
                        Ext.MessageBox.show({
                            title:'提示框',
                            msg: ' 删除成功 ',                
                            buttons:{
                                'yes':'确定'
                            },
                            fn: showResult2
                        });
                        function showResult2(btn){
                            if(btn=="yes"){
                                grid.store.reload();
                            }
                        } 
                    }else if(ret="false"){
                        Ext.Msg.alert('提示','删除失败！');
                    }
                }
            }
        }
   
        function  datastore(){
    	
            formStore.paraid = Ext.ComponentMgr.get("paraid").getValue();
            formStore.repid = Ext.ComponentMgr.get("repid").getValue();
            formStore.paraname = Ext.ComponentMgr.get("paraname").getValue();
            formStore.sourcedep = Ext.ComponentMgr.get("sourcedep").getValue();
            formStore.contactor = Ext.ComponentMgr.get("contactor").getValue();
            formStore.paraunit = Ext.ComponentMgr.get("paraunit").getValue();
            formStore.updatatime = Ext.ComponentMgr.get("updatatime").getValue();
            formStore.issaved = Ext.ComponentMgr.get("issaved").getValue();

        }		
    
        function  clearstore(){
    	
            Ext.ComponentMgr.get("paraid").setValue("");
            Ext.ComponentMgr.get("repid").setValue("");
            Ext.ComponentMgr.get("paraname").setValue("");
            Ext.ComponentMgr.get("sourcedep").setValue("");
            Ext.ComponentMgr.get("contactor").setValue("");
            Ext.ComponentMgr.get("paraunit").setValue("");
            Ext.ComponentMgr.get("updatatime").setValue("");
            Ext.ComponentMgr.get("issaved").setValue("");

        }
    
        win.show(this);

    }
}

  